package com.voicechat.firstmet.utils;

import android.content.Context;
import android.os.CountDownTimer;
import android.widget.TextView;

import com.voicechat.firstmet.R;


/**
 * @author Android
 * 倒计时 工具类
 */

public class TimerUtil extends CountDownTimer {
    TextView mTextView;
    int count = 0;//启动次数
    Context context;

    public TimerUtil(long countDownTime, TextView textView, Context context) {
        super(countDownTime * 1000, 1000);
        this.context = context;
        mTextView = textView;
    }

    public void myStart(int count) {
        this.start();
        this.count = count;
    }


    @Override
    public void onTick(long millisUntilFinished) {
        mTextView.setClickable(false);
       /* if (count > 2) {
            mTextView.setTextColor(context.getResources().getColor(R.color.common_blue));
            mTextView.setText("" + millisUntilFinished / 1000 + "s");
        } else {*/
            mTextView.setTextColor(context.getResources().getColor(R.color.color666666));
            mTextView.setText("(" + millisUntilFinished / 1000 + ")重新获取验证码");
        //}

    }

    @Override
    public void onFinish() {
        this.cancel();
        mTextView.setClickable(true);
        /*if (count >= 2) {
            mTextView.setTextColor(context.getResources().getColor(R.color.common_blue));
            mTextView.setText("重新发送");
        } else {*/
            mTextView.setTextColor(context.getResources().getColor(R.color.colorFF3B5E));
            mTextView.setText("重新获取验证码");
       // }

    }

}
